﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Perovich.GameObjects.Attributes;
using Microsoft.Xna.Framework;

namespace Perovich.GameObjects.Components
{
    [ComponentDependency(typeof(Velocity2D))]
    [AutomaticProperty("XXX", "Acceleration2D.X", XmlSummary = "Gets or sets the X acceleration of the entity.", XmlReturns = "A <see cref=\"System.Single\">float</see> that is the entity's X acceleration.")]
    [AutomaticProperty("YYY", "Acceleration2D.Y", XmlSummary = "Gets or sets the Y acceleration  of the entity.", XmlReturns = "A <see cref=\"System.Single\">float</see> that is the entity's Y acceleration.")]
    [AutomaticProperty("Acceleration", "Acceleration2D.Acceleration", XmlSummary = "Gets or sets the acceleration of the entity.", XmlReturns = "A <see cref=\"vector2\">Vector2</see> that is the entity's acceleration.")]
    [AutomaticImport("Microsoft.Xna.Framework", false)]
    [AutomaticImport("Microsoft.Xna.Framework", true)]
    public sealed class Acceleration2D : EntityComponent
    {
        Vector2 acceleration;
        Velocity2D velocity;
        public Acceleration2D()
        {
            acceleration = Vector2.Zero;
        }

        public float X
        {
            get
            {
                return acceleration.X;
            }
            set
            {
                acceleration = new Vector2(value, acceleration.Y);
            }
        }

        public float Y
        {
            get
            {
                return acceleration.Y;
            }
            set
            {
                acceleration = new Vector2(acceleration.X, value);
            }
        }

        public Vector2 Acceleration
        {
            get
            {
                return acceleration;
            }
            set
            {
                acceleration = value;
            }
        }

        public override void Initialize()
        {
            velocity = Owner.Find<Velocity2D>();
            UpdateOrder = Constants.AccelerationUpdateOrder;
            base.Initialize();
        }

        public override void Update(GameTime gameTime)
        {
            velocity.Velocity += Acceleration * (float)gameTime.ElapsedGameTime.TotalSeconds;
            base.Update(gameTime);
        }

    }
}
